﻿#pragma once

#include "VertexArray.h"

/**
 * Data layout:
 *  00-08: y  coordinates
 *  09-13: x  coordinates
 *  14-18: z  coordinates
 *  19-20: uv coordinates
 *  21-30: texture index
 */
class BlockVertexPacked
{
private:
  uint32_t data = 0;
  uint32_t data2 = 0;
  uint32_t subOffset = 0;
  glm::vec3 normal{0.f};

  void SetUv(bool x, bool y);

public:
  BlockVertexPacked() = default;
  BlockVertexPacked(const glm::ivec3 &position, const glm::bvec2 &uv);

  void SetOffset(uint32_t x, uint32_t y, uint32_t z);
  void SetSubOffset(uint8_t x, uint8_t y, uint8_t z);
  void SetNormal(const glm::vec3 &normal);
  void SetTexture(uint8_t x, uint8_t y);
  void SetAnimSize(uint16_t size);
  void SetOcclusionLevel(uint8_t occlusionLevel);

  glm::ivec3 GetPosition() const;

  static std::vector<VertexAttribute> VertexAttributes()
  {
    return {
        VertexAttribute(1, VertexAttribute::UInt),
        VertexAttribute(1, VertexAttribute::UInt),
        VertexAttribute(1, VertexAttribute::UInt),
        VertexAttribute(3, VertexAttribute::Float),
    };
  }
};

static_assert(sizeof(BlockVertexPacked) == (sizeof(uint32_t) * 3 + sizeof(glm::vec3)), "The BlockVertexPacked struct must not have padding");
